import { Body, Controller, Get, Post,Param,Delete, Put, Inject} from '@nestjs/common';
import { AdminService } from './admin.service';
import { BoyService } from '../boy/boy.service';


@Controller('admin')
export class AdminController {
    constructor(
        @Inject('Config') private shopName:String,
        private adminService:AdminService,
        private BoyService:BoyService
    ) {}

    @Post('/addAdmin')
    addAdmin(@Body() admin:any){
        let res = this.adminService.addAdmin(admin)
        return {
            code:0,
            msg:'添加成功'
        };
    }

    @Delete('/delAdmin/:id')
    delAdmin(@Param() id:number){
        this.adminService.delAdmin(id)
        return {
            code:0,
            msg:'删除成功'
        };
    }

    @Put("/putAdmin")
    putAdmin(@Body() admin:any){
        this.adminService.updateAdmin(admin)
        return {
            code:0,
            msg:'修改成功'
        };
    }

    @Get('/getAdmin')
    getAdmin(){
        return this.adminService.getAdmin()
    }

    @Get('/finAdminName/:name')
    getAdminName(@Param() params){
        return this.adminService.getAdminName(params.name)
    }

    @Get('/corstest')
    corsTest():object{
        return {
            code:0,
            msg:'跨域测试成功'
        };
    }

    @Get('/getShopName')
    getShopName():String{
        return this.shopName;
    }


    @Get('/getBoy')
    getBoy():any{
        return this.BoyService.findAll();
    }

}

